package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.pojo.CommonResult;
import com.atguigu.springcloud.pojo.Payment;
import com.atguigu.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * Author:   wj
 * Date:     2020/5/21 11:44
 * Description:
 */
@RestController
@RequestMapping("/payment")
@Slf4j
public class PaymentController {
    @Autowired
    PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @PostMapping("/")
    public CommonResult<Object> save(@RequestBody Payment payment){
        paymentService.save(payment);
        log.info("端口号：{}",serverPort);
        return new CommonResult<Object>(200,"添加成功",null);
    }

    @GetMapping("/{id}")
    public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
        log.info("端口号：{}",serverPort);
        return new CommonResult<Payment>(200,"查询成功",paymentService.getPaymentBYId(id));
    }
}
